/**
 * 
 */
package tests;

import java.io.IOException;
import java.util.logging.*;
public class Log {

	//Create the one and only logger
	static Log instance;
	static FileHandler handler;
	private static String name = "";
	private static Logger diagnosticLog = Logger.getLogger ("_rdflog");
	static{
		try {
		    // Create an appending file handler
		    boolean append = true;
		    int limit = 1000000000; // 1 Mb
		    int numLogFiles = 3;
//		    FileHandler handler = new FileHandler("//home//smriti//workspace//rdfDBI//src//tests//rdfLogFile%g.log", limit, numLogFiles ,append);
//		    FileHandler handler = new FileHandler("//home//smriti//workspace//rdfDBI//src//tests//rdfLogFile0.log",append);
		    handler = new FileHandler("//home//indrani//Downloads//minjava//DBI_phase2//src//tests//rdfLogFile0.log" ,append);
		    handler.setFormatter(new Formatter() {
		         public String format(LogRecord rec) {
		             StringBuffer buf = new StringBuffer(1000);
		             buf.append(new java.util.Date());
		             buf.append(' ');
		             buf.append(rec.getLevel());
		             buf.append(' ');
		             buf.append(formatMessage(rec));
		             buf.append('\n');
		             return buf.toString();
		             }
		           });
		    // Add to the desired logger
		    diagnosticLog.addHandler(handler);
		} catch (IOException e) {
		}
	}

	

	/** Creates a new instance of logWrapper */
	private Log () {
	}

	public static void flush () {
		handler.flush();
	}
	
	public static Log getInstance (String classname) {
		name = classname;
		if(instance == null) {
			instance = new Log ();
		}

		return instance;
	}

	public void write ( String msg) {
		diagnosticLog.log(Level.INFO, name + " " + msg );
	}
}